
/* 
 * Since 2008 - 2012
 */
package com.hh.bss.talent.controller;

import static com.hh.bss.util.extjs.JsonHelper.outJson;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.hh.bss.auth.client.OnlineManager;
import com.hh.bss.auth.client.OnlineUser;
import com.hh.bss.base.BaseSpringController;
import com.hh.bss.common.page.Page;
import com.hh.bss.common.page.PageRequest;
import com.hh.bss.talent.entity.CvAttachment;
import com.hh.bss.talent.entity.CvAttachmentLog;
import com.hh.bss.talent.service.CvAttachmentLogService;
import com.hh.bss.talent.vo.query.CvAttachmentLogQuery;
import com.hh.bss.util.extjs.ExtJsPageHelper;
import com.hh.bss.util.extjs.ListRange;


@Controller
public class CvAttachmentLogController extends BaseSpringController{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	@Autowired
	private CvAttachmentLogService  cvAttachmentLogService;
	
	
	java.lang.Integer id = null;
	private String[] items;

	
	public void setId(java.lang.Integer val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}



	/**
	 * ExtGrid使用
	 * 列表
	 * @throws IOException
	 */
	public void list(HttpServletRequest request,HttpServletResponse response,CvAttachmentLogQuery query) throws IOException
	{
		OnlineManager onlineManager=super.getOnlineManager(request, response);
		if (onlineManager!=null){
			OnlineUser onlineUser=onlineManager.getOnlineUser();
			query.setOnlineUser(onlineUser);
		}
		PageRequest<Map> pr = ExtJsPageHelper.createPageRequestForExtJs(request, DEFAULT_SORT_COLUMNS);
		
		Page page = cvAttachmentLogService.findPage(query);
		
		List<CvAttachmentLog> CvAttachmentLoglist = (List) page.getResult();
		ListRange<CvAttachmentLog> resultList = new ListRange<CvAttachmentLog>();
		resultList.setRows(CvAttachmentLoglist);
		resultList.setTotal(page.getTotalCount());
		resultList.setMessage("ok");
		resultList.setSuccess(true);
		outJson(response,resultList);
	}


	
	/**
	 * extGrid删除
	 * @throws IOException
	 */
	public void delete(HttpServletRequest request,HttpServletResponse response) throws IOException
	{
		String ids = request.getParameter("ids");
		String[] idarray = ids.split(",");
		Map<String, Object> result = new HashMap<String, Object>();
		try
		{
			for (int i = 0; i < idarray.length; i++)
			{
				java.lang.Integer id = new java.lang.Integer((String)idarray[i]);
				//查记录
				CvAttachmentLog cvAttachmentLog=(CvAttachmentLog)cvAttachmentLogService.getById(id);				
				Integer cvId=null;
				if (cvAttachmentLog!=null) cvId=cvAttachmentLog.getCvId();
				cvAttachmentLogService.removeById(id);
			}
			result.put("success", true);
			result.put("msg", "删除成功");
		}
		catch (Exception e)
		{
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(response,result);
	}
	
	
}
